// This is autogenerated file. Do not edit!

package models.autogenerated;

class UsersInfoManager
{
	var db : orm.Db;
	var orm : models.Orm;
	public var query(get, never) : orm.SqlQuery<models.UsersInfo>;

	function get_query() : orm.SqlQuery<models.UsersInfo>
	{
		return new orm.SqlQuery<models.UsersInfo>("users_info", db, this);
	}

	public function new(db:orm.Db, orm:models.Orm) : Void
	{
		this.db = db;
		this.orm = orm;
	}

	function newModelFromParams(id:String, username:String, first_name:String, second_name:String, pinned_sentence:String, image_src:String, join_date:Float, last_login:Float) : models.UsersInfo
	{
		var _obj = new models.UsersInfo(db, orm);
		_obj.id = id;
		_obj.username = username;
		_obj.first_name = first_name;
		_obj.second_name = second_name;
		_obj.pinned_sentence = pinned_sentence;
		_obj.image_src = image_src;
		_obj.join_date = join_date;
		_obj.last_login = last_login;
		return _obj;
	}

	function newModelFromRow(d:Dynamic) : models.UsersInfo
	{
		var _obj = new models.UsersInfo(db, orm);
		_obj.id = Reflect.field(d, 'id');
		_obj.username = Reflect.field(d, 'username');
		_obj.first_name = Reflect.field(d, 'first_name');
		_obj.second_name = Reflect.field(d, 'second_name');
		_obj.pinned_sentence = Reflect.field(d, 'pinned_sentence');
		_obj.image_src = Reflect.field(d, 'image_src');
		_obj.join_date = Reflect.field(d, 'join_date');
		_obj.last_login = Reflect.field(d, 'last_login');
		return _obj;
	}

	public function where(field:String, op:String, value:Dynamic) : orm.SqlQuery<models.UsersInfo>
	{
		return query.where(field, op, value);
	}

	public function get(id:String) : models.UsersInfo
	{
		return getBySqlOne('SELECT * FROM `users_info` WHERE `id` = ' + db.quote(id));
	}

	public function create(id:String, username:String, first_name:String, second_name:String, pinned_sentence:String, image_src:String, join_date:Float, last_login:Float) : models.UsersInfo
	{
		db.query('INSERT INTO `users_info`(`id`, `username`, `first_name`, `second_name`, `pinned_sentence`, `image_src`, `join_date`, `last_login`) VALUES (' + db.quote(id) + ', ' + db.quote(username) + ', ' + db.quote(first_name) + ', ' + db.quote(second_name) + ', ' + db.quote(pinned_sentence) + ', ' + db.quote(image_src) + ', ' + db.quote(join_date) + ', ' + db.quote(last_login) + ')');
		return newModelFromParams(id, username, first_name, second_name, pinned_sentence, image_src, join_date, last_login);
	}

	public function createNamed(data:{ id:String, username:String, first_name:String, second_name:String, pinned_sentence:String, image_src:String, join_date:Float, last_login:Float }) : models.UsersInfo
	{
		db.query('INSERT INTO `users_info`(`id`, `username`, `first_name`, `second_name`, `pinned_sentence`, `image_src`, `join_date`, `last_login`) VALUES (' + db.quote(data.id) + ', ' + db.quote(data.username) + ', ' + db.quote(data.first_name) + ', ' + db.quote(data.second_name) + ', ' + db.quote(data.pinned_sentence) + ', ' + db.quote(data.image_src) + ', ' + db.quote(data.join_date) + ', ' + db.quote(data.last_login) + ')');
		return newModelFromParams(data.id, data.username, data.first_name, data.second_name, data.pinned_sentence, data.image_src, data.join_date, data.last_login);
	}

	public function createOptional(data:{ id:String, ?username:String, ?first_name:String, ?second_name:String, ?pinned_sentence:String, ?image_src:String, ?join_date:Float, ?last_login:Float }) : models.UsersInfo
	{
		createOptionalNoReturn(data);
		return get(data.id);
	}

	public function createOptionalNoReturn(data:{ id:String, ?username:String, ?first_name:String, ?second_name:String, ?pinned_sentence:String, ?image_src:String, ?join_date:Float, ?last_login:Float }) : Void
	{
		var fields = [];
		var values = [];
		fields.push('`id`'); values.push(db.quote(data.id));
		if (Reflect.hasField(data, 'username')) { fields.push('`username`'); values.push(db.quote(data.username)); }
		if (Reflect.hasField(data, 'first_name')) { fields.push('`first_name`'); values.push(db.quote(data.first_name)); }
		if (Reflect.hasField(data, 'second_name')) { fields.push('`second_name`'); values.push(db.quote(data.second_name)); }
		if (Reflect.hasField(data, 'pinned_sentence')) { fields.push('`pinned_sentence`'); values.push(db.quote(data.pinned_sentence)); }
		if (Reflect.hasField(data, 'image_src')) { fields.push('`image_src`'); values.push(db.quote(data.image_src)); }
		if (Reflect.hasField(data, 'join_date')) { fields.push('`join_date`'); values.push(db.quote(data.join_date)); }
		if (Reflect.hasField(data, 'last_login')) { fields.push('`last_login`'); values.push(db.quote(data.last_login)); }
		db.query('INSERT INTO `users_info`(' + fields.join(", ") + ') VALUES (' + values.join(", ") + ')');
	}

	public function delete(id:String) : Void
	{
		db.query('DELETE FROM `users_info` WHERE `id` = ' + db.quote(id) + ' LIMIT 1');
	}

	public function getAll(_order:String=null) : Array<models.UsersInfo>
	{
		return getBySqlMany('SELECT * FROM `users_info`' + (_order != null ? ' ORDER BY ' + _order : ''));
	}

	public function getBySqlOne(sql:String) : models.UsersInfo
	{
		var rows = db.query(sql + ' LIMIT 1');
		if (rows.length == 0) return null;
		return newModelFromRow(rows.next());
	}

	public function getBySqlMany(sql:String) : Array<models.UsersInfo>
	{
		var rows = db.query(sql);
		var list : Array<models.UsersInfo> = [];
		for (row in rows)
		{
			list.push(newModelFromRow(row));
		}
		return list;
	}
}